var app = getApp()

Page({
  data: {
    goodsCode: "",
    goodsName: "铅笔岛 校园三件套 (10人份)",
    freePost: 0,
    price: 29,
    orderPrice: 29.9,
    buyNum: 1,
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    windowWidth: 300,
    imgUrls:[{
      url:'../../images/11.jpg'
    }, {
      url: '../../images/22.jpg'
    }]
  },
  buyGoods:function(event){
    var that = this;
    var goodsCode = event.currentTarget.dataset.goodsCode;

    wx.navigateTo({
      url: '../goods/goods?goodsCode='+goodsCode
    })
  },
  onLoad: function (object) {
    var that = this

    app.checkLogin(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    });

    if (!app.globalData.userInfo) {
      app.getUserInfo(function (userInfo) {
        //更新数据
        that.setData({
          userInfo: userInfo
        })
      })
    }

    var systemInfo = wx.getSystemInfoSync()
    that.setData({
      windowWidth: systemInfo.windowWidth
    });


    wx.request({
      url: app.globalData.serverUrl + '/app/mp',
      method: 'post',
      dataType: 'json',
      data: {
        messageId: 'queryGoodsList',
        body: {}
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.success) {
          var goodsList = res.data.goodsList;
          for (var i = 0; i < goodsList.length; i++) {
            var imgDetails = goodsList[i].imgDetails;
            for (var j = 0; j < imgDetails.length;j++){
              imgDetails[j]['width'] = systemInfo.windowWidth-30
              imgDetails[j]['height'] = systemInfo.windowWidth-30
            }
            // goodsList[i].imgDetails = imgDetails;
          }
          that.setData({
            goodsList: goodsList
          });
        }
      }
    })

  }
})